package cn.tedu.ivos.user.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.user.pojo.dto.UserLoginParam;
import cn.tedu.ivos.user.pojo.dto.UserQuery;
import cn.tedu.ivos.user.pojo.dto.UserSaveParam;
import cn.tedu.ivos.user.pojo.entity.User;
import cn.tedu.ivos.user.pojo.vo.UserVO;
import cn.tedu.ivos.user.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    private UserService userService;

    private static final Logger log = LoggerFactory.getLogger(UserController.class);

    @PostMapping("login")
    public JsonResult login(@RequestBody UserLoginParam userLoginParam) {
        log.info("用户名：{}，密码：{}", userLoginParam.getUsername(), userLoginParam.getPassword());
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }
    @PostMapping("save")
    public JsonResult save( UserSaveParam userSaveParam) {
        log.info("保存用户：UserSaveParam={}",userSaveParam);
        userService.saveUser(userSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("select")
    public JsonResult select(UserQuery userQuery) {
        log.info("查询用户：UserSelectParam={}",userQuery);
        return JsonResult.ok(userService.select(userQuery));
    }

    @PostMapping("/update/password/{userId}")
    public JsonResult updatePassword(@PathVariable Long userId) {
        log.info("修改密码，用户ID：{},新密码：{}", userId);
        userService.updatePassword(userId);
        return JsonResult.ok();
    }

    @PostMapping("/update/status/{userId}/{status}")
    public JsonResult updatePassword(@PathVariable Long userId, @PathVariable String status) {
        log.debug("修改用户状态，用户ID：{},新状态：{}", userId, status);
        userService.updateStatus(userId, status);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{userId}")
    public JsonResult delete(@PathVariable Long userId) {
        log.debug("删除用户，用户ID：{}", userId);
        userService.delete(userId);
        return JsonResult.ok();
    }
}
